package com.servlet;

import com.dao.WriteJsondao;
import com.dao.searchdao;
import com.dao.searchdaoimpl;
import com.entity.productdetails;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

public class search extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        String message=req.getParameter("searchBox");
        searchdao s=new searchdaoimpl();
        Set<productdetails> list = new HashSet<>(s.search(message));
        if(s.search(message).size()!=0)
        {
            req.getSession().setAttribute("messages",list);
            req.getRequestDispatcher("/sousuotiaozhuan.jsp").forward(req,resp);
        }
        else
        {
            req.getSession().setAttribute("messagess","没有找到相关信息");
            req.getRequestDispatcher("/sousuotiaozhuan.jsp").forward(req,resp);
            req.getSession().setAttribute("messagess","");
        }
    }
//        doGet(req, resp);
}


